//
//  MBLoginUserModelArchieveTool.m
//  MobellCloud_ios
//
//  Created by cherry pu on 2018/1/4.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBLoginUserModelArchieveTool.h"

@implementation MBLoginUserModelArchieveTool

+ (void)userInfoAchieveToFile:(MBLoginUserModel *)account
{
    NSString * doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * filePath = [doc stringByAppendingPathComponent:@"userInfo.data"];
    [NSKeyedArchiver archiveRootObject:account toFile:filePath];
}

+ (MBLoginUserModel *)userInfoUnAchieveFromFile
{
    NSString * doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * filePath = [doc stringByAppendingPathComponent:@"userInfo.data"];
    return [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}


+ (void)shippingAchieveToFile:(NSArray *)shippingArray
{
    NSString * doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * filePath = [doc stringByAppendingPathComponent:@"shipping.data"];
    [NSKeyedArchiver archiveRootObject:shippingArray toFile:filePath];
}

+ (NSArray *)shippingUnAchieveFromFile
{
    NSString * doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * filePath = [doc stringByAppendingPathComponent:@"shipping.data"];
    return [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}

+ (void)removeSelfUserFromDisk
{
    NSString * doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * filePath = [doc stringByAppendingPathComponent:@"userInfo.data"];
    NSFileManager * fileManager = [NSFileManager defaultManager];
    if ([fileManager isDeletableFileAtPath:filePath]) {
        [fileManager removeItemAtPath:filePath error:nil];
    }
}

@end
